#pragma once
#include<vulkan/vulkan.hpp>

class SyncObject
{
private:
    /* data */
    vk::Device logicDevice;
public:
    vk::Fence fence;
    vk::Semaphore imageAvailableSemaphore;
    vk::Semaphore renderFinishedSemaphore;
public:
    SyncObject(vk::Device device):logicDevice(device)
{
    vk::SemaphoreCreateInfo info;
    imageAvailableSemaphore = device.createSemaphore(info);
    if (!imageAvailableSemaphore)
    {
        throw std::runtime_error("create image available semaphore field!");
    }
    
    renderFinishedSemaphore = device.createSemaphore(info);
    if (!renderFinishedSemaphore)
    {
        throw std::runtime_error("create render finished semaphore field!");
    }

    vk::FenceCreateInfo fenceinfo;
    fenceinfo.setFlags(vk::FenceCreateFlagBits::eSignaled);
    fence = logicDevice.createFence(fenceinfo);

}
    ~SyncObject(){   }

    void destroy(){
    if  (fence)
    {
        logicDevice.destroyFence(fence);
    }
    if (imageAvailableSemaphore)
    {
        logicDevice.destroySemaphore(imageAvailableSemaphore);
    }
    if (renderFinishedSemaphore)
    {
        logicDevice.destroySemaphore(renderFinishedSemaphore);
    }
}

};

